// pages/article/info.js
var xrRequest = require('../../vendor/hope-sdk/core/request.js');
var xrSdk = require('../../vendor/hope-sdk/index.js');
var config = require('../../config.js');
const WxParse = require('../../vendor/wxParse/wxParse.js');
const util = require('../../utils/util.js')
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    hostUrl: config.service.hostUrl,
    id: 0,
    article: {}
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      id: options.id
    });
    this.onPullDownRefresh();
  },
  initData: function () {
    this.setData({
      article: {}
    });
  },
  getList: function () {
    var that = this;
    const id = this.data.id;
    
    xrRequest.request(app,{
      url: config.service.articleInfo,
      data: { id: id },
      login: false,
      success: (response) => {
        const data = response.data;
        console.log(data);
        if (data.code == 1) {
          this.setData({
            article: data.data,
          })
          WxParse.wxParse('articlecontent', 'html', data.data.content, that, 5);
        }
      },
      fail: (error) => {
        util.showModel('加载失败', error);
        console.log('加载失败', error);
      }
    });
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    console.info('onPullDownRefresh')
    this.initData();
    this.getList();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})